package com.jml.代理模式.五期.注解失效.service.aop;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;


@Component
@Aspect
@Slf4j
public class ExtAsyncAop {

    private ExecutorService executorService;

    public ExtAsyncAop() {
        executorService = Executors.newFixedThreadPool(10);
    }

    @Around(value = "@annotation(com.jml.代理模式.五期.注解失效.service.ext.ExtAsync)")
    public void doBefore(ProceedingJoinPoint joinPoint) throws Throwable {
        // 直接获取到方法上有加上ExtAsync
        log.info(">>>拦截到我们方法上有加上ExtAsync");
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                // 执行我们的目标方法
                try {
                    joinPoint.proceed();
                } catch (Throwable throwable) {
                    throwable.printStackTrace();
                }
            }
        });

    }
}
